package com.kuang.test;

import java.util.Random;
import java.util.Scanner;

/**
 * @ClassName DoubleColorBallReward
 * @Description: 双色球中奖算法
 * @Author: Sunny
 * @Create: 2023-10-09 09:25
 * @Version 1.0
 **/
public class DoubleColorBallReward {
    public static void main(String[] args) {
        /*
         * 模拟双色球, 红球6个1-33号码中选择且不能重复, 篮球1个 1-16中选择
         * 用户购买双色球,判断用户的数字与中奖号码有多少相同,做出对应奖项
         * */
        int[] arr = getNumberList();

        for (int k : arr) {
            System.out.print(k + " ");
        }
        System.out.println("===============");
        int[] userInput = userInputNumber();
        int redNumber = 0;
        int blueNumber = 0;
        // 判断用户输入的值和系统号码是否相同
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = 0; j < userInput.length - 1; j++) {
                if (arr[i] == userInput[j]) {
                    redNumber++;
                    break;
                }
            }
        }

        // 判断蓝球的数值是否相等
        if (arr[arr.length - 1] == userInput[userInput.length - 1]) {
            blueNumber++;
        }

        System.out.println("红球中了 " + redNumber + " 个, 蓝球中了 " + blueNumber + " 个");

        if (redNumber == 6 && blueNumber == 1) {
            System.out.println("恭喜你,中了1000万");
        } else if (redNumber == 6 && blueNumber == 0) {
            System.out.println("恭喜你,中了500万");
        } else if (redNumber == 5 && blueNumber == 1) {
            System.out.println("恭喜你,中了3000元");
        } else if ((redNumber == 4 && blueNumber == 1) || (redNumber == 5 && blueNumber == 0)) {
            System.out.println("恭喜你,中了2000元");
        } else if ((redNumber == 3 && blueNumber == 1) || (redNumber == 2 && blueNumber == 1)) {
            System.out.println("恭喜你, 中奖10元");
        } else if ((redNumber == 1 && blueNumber == 1) || (redNumber == 0 && blueNumber == 1)) {
            System.out.println("恭喜你, 中奖5元");
        } else {
            System.out.println("谢谢惠顾,谢谢光临");
        }
    }

    // 获取双色球的数组列表
    public static int[] getNumberList() {
        // 获取数组
        int[] list = new int[7];
        Random rand = new Random();
        for (int i = 0; i < 6; ) {
            // 生成红色球数组
            int randNumber = rand.nextInt(33) + 1;
            boolean flag = contains(list, randNumber);
            if (!flag) {
                list[i] = randNumber;
                i++;
            }
        }
        int blue = rand.nextInt(16) + 1;
        list[list.length - 1] = blue;
        return list;
    }

    public static boolean contains(int[] arr, int number) {
        for (int j : arr) {
            if (j == number) {
                return true;
            }
        }
        return false;
    }

    // 获取用户球的数组
    public static int[] userInputNumber() {
        // 红球6个, 篮球一个
        // 键盘录入,让用户输入彩票号码
        int[] arr = new int[7];
        Scanner scanner = new Scanner(System.in);
        // 获取红球的数组
        for (int i = 0; i < 6; ) {
            System.out.println("请输入第" + (i + 1) + "个红球的数字");
            int redNumber = scanner.nextInt();
            // 判断红球是否超出范围
            if (redNumber >= 1 && redNumber <= 33) {
                boolean flag = contains(arr, redNumber);
                // 如果数字不存在,写入数组中
                if (!flag) {
                    arr[i] = redNumber;
                    i++;
                } else {
                    System.out.println("数字已存在,请重新输入");
                }
            } else {
                System.out.println("不在红球的范围内,请重新输入");
            }
        }


        while (true) {
            System.out.println("请输入蓝球的数字");
            int blueNumber = scanner.nextInt();
            if (blueNumber >= 1 && blueNumber <= 16) {
                arr[arr.length - 1] = blueNumber;
                break;
            }
        }
        return arr;
    }

}